package gae.util.http.client;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Parameter {
    
    private Map<String, String> params = new HashMap<String, String>();
    
    
    public void set(String key, String value) {
        params.put(key, value);
    }
    
    public String get(String key) {
        return params.get(key);
    }
    
    public boolean hasParameter() {
        if (params.size() > 0) {
            return true;
        }
        return false;
    }
    
    public String toParameterString() {
        if (hasParameter()) {
            StringBuilder sb = new StringBuilder();
            Iterator<String> ite = params.keySet().iterator();
            while (ite.hasNext()) {
                String key = ite.next();
                sb.append(key);
                sb.append("=");
                sb.append(params.get(key));
                if (ite.hasNext()) {
                    sb.append("&");
                }
            }
            return sb.toString();
        }
        return null;
    }
    
}
